<template>
	<view class="container">
		<!-- <tui-list-cell :hover="false" :lineLeft="false" v-if="istrue">
			<view class="tui-cell-input">
				<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
				<input :value="old_pay_password" placeholder="请输入原始支付密码" placeholder-class="tui-phcolor" type="password" :auto-focus="true" :focus="true" maxlength="40" @input="inputOldPassword" />
			   <icon type="clear" :size="14" color="#bfbfbf" v-show="old_pay_password" @tap="clearOldPasswordInput"></icon>
			</view>
		</tui-list-cell> -->
		<tui-list-cell :hover="false" :lineLeft="false">
			<view class="tui-cell-input">
				<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
				<input :value="pay_password" placeholder="请输入支付密码" placeholder-class="tui-phcolor" type="password" :auto-focus="true" :focus="true" maxlength="6" @input="inputPassword" />
			   <icon type="clear" :size="14" color="#bfbfbf" v-show="pay_password" @tap="clearPasswordInput"></icon>
			</view>
		</tui-list-cell>
		<tui-list-cell :hover="false" :lineLeft="false">
			<view class="tui-cell-input">
				<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
				<input :value="comf_pay_password" placeholder="请再次输入支付密码" placeholder-class="tui-phcolor" type="password" :auto-focus="true" :focus="true" maxlength="6" @input="inputComfPassword" />
			   <icon type="clear" :size="14" color="#bfbfbf" v-show="comf_pay_password" @tap="clearComfPasswordInput"></icon>
			</view>
		</tui-list-cell>
		<tui-list-cell :hover="false" :lineLeft="false" backgroundColor="transparent">
							<view class="tui-cell-input">
								<tui-icon name="shield" color="#6d7a87" :size="20"></tui-icon>
								<input placeholder="请输入验证码" placeholder-class="tui-phcolor" type="text" maxlength="6" @input="inputCode" />
		<tui-button width="182rpx" height="56rpx" :size="24" type="warning" shape="circle" @click="btnSend">{{ btnSendText }}</tui-button>
							</view>
						</tui-list-cell>
		<view class="tui-btn-box">
			<tui-button shadow height="88rpx" shape="circle" type="danger" @click="savePayPassword()">确定</tui-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
		
				istrue:false,
				set_type:0,
				
				pay_password: '',
				old_pay_password: '1',
				comf_pay_password: '',
				btnSendText: '获取验证码', //倒计时格式：(60秒),
				pwd: false,
				noClick: false,
				sms_code:'',
				btnText: '获取验证码' //倒计时格式：(60秒)
			}
		},
		onShow() {
			this.tui.haslogin();
			if(this.tui.isLogin()){
				this.userinfo = this.tui.getUserInfoData();
				this.init();
			}
		},
		methods: {
			init(){
				let token = this.tui.getToken();
	
				let datas={
					token:token,
					set_type:this.set_type
				};
				let paypassword=this.tui.request('user','post',datas,1000,1,'','getPayPassword');
				Promise.resolve(paypassword).then((value)=>{
				   if(value.code==200){
					   if(value.data){
						 this.set_type=value.data;  
					   }
					   this.istrue=value.data
				   }
				})
			},
			inputOldPassword(e) {
				this.old_pay_password = e.detail.value;
			},
			inputCode(e) {
				this.sms_code = e.detail.value;
			},
			clearOldPasswordInput() {
				this.old_pay_password = '';
			},
			inputPassword(e) {
				this.pay_password = e.detail.value;
			},
			clearPasswordInput() {
				this.pay_password = '';
			},
			inputComfPassword(e) {
				this.comf_pay_password = e.detail.value;
			},
			clearComfPasswordInput() {
				this.comf_pay_password = '';
			},
			savePayPassword(){
				let token = this.tui.getToken();
				
				if(this.pay_password!=this.comf_pay_password){
					this.tui.toast('两次密码不一致');
					return;
				}
				let datas={
					token:token,
					sms_code: this.sms_code,
					pay_pwd:this.pay_password,
					set_type:this.set_type
				};
				let paypassword=this.tui.request('user','post',datas,1000,1,'','setPayPwd');
				Promise.resolve(paypassword).then((value)=>{
				   if(value.code==200){
				   	this.tui.toast(value.message);
					setTimeout(() => {
						uni.navigateBack()
					}, 1000);
				   }else{
				   	this.tui.toast(value.message);
				   }
				})
			},
			btnSend(seconds){
				let datas={
						mobile: this.mobile,
						sms_type: 2,
					};
				let regs=this.tui.request('user','post',datas,1000,1,'','sendSms');
				Promise.resolve(regs).then((value)=>{
				   if(value.code==200){
					    this.disableds=true;
					    this.tui.toast(value.message);
						this.btnSendText = '请稍候...';
						setTimeout(() => {
							this.doLoop(60);
						}, 500);
				   }else{
				   	this.tui.toast(value.message);
				   }
				})
			},
			doLoop: function(seconds) {
				seconds = seconds ? seconds : 60;
				this.btnSendText = seconds + 's后获取';
				let countdown = setInterval(() => {
					if (seconds > 0) {
						this.btnSendText = seconds + 's后获取';
						--seconds;
					} else {
						this.btnSendText = '获取验证码';
						this.disableds = false;
						clearInterval(countdown);
					}
				}, 1000);
			},
		}
	}
</script>

<style lang="scss">
.container {
	padding-top: 20rpx;
	.tui-cell-input {
		width: 100%;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		
		input {
			flex: 1;
			padding-left: $uni-spacing-row-base;
		}
	}
	.tui-btn-box {
		padding: 40rpx 30rpx 10rpx 30rpx;
		box-sizing: border-box;
	}
}
</style>
